package com.qp.bookkeeping.common.model.rsp;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xutianqi
 */
@Data
public class BaseRsp<T> {
    private String rspMsg = "success";
    private String rspCode = "0000";
    private T result;

    public static <T> BaseRsp<T> success(T result) {
        BaseRsp<T> baseRsp = new BaseRsp<>();
        baseRsp.setRspCode("0000");
        baseRsp.setRspMsg("成功！");
        baseRsp.setResult(result);
        return baseRsp;
    }

    public static BaseRsp success() {
        BaseRsp baseRsp = new BaseRsp<>();
        baseRsp.setRspCode("0000");
        baseRsp.setRspMsg("成功！");
        return baseRsp;
    }

    public static <T> BaseRsp<T> fail(String rspCode, String rspMsg) {
        BaseRsp<T> baseRsp = new BaseRsp<>();
        baseRsp.setRspCode(StringUtils.isBlank(rspCode) ? "5555" : rspCode);
        baseRsp.setRspMsg(rspMsg);
        return baseRsp;
    }
}
